package leetcode.weekly.week298;

//Solution2Test
public class Solution2 {

	public int minimumNumbers(int num, int k) {
		if (num == 0) {
			return 0;
		}
		int last = num % 10;
		if (k == 0) {
			return last == 0 ? 1 : -1;
		}
		int ans1 = Integer.MAX_VALUE;
		for (int i = 0; i < 10; i++) {
			int num1 = last + 10 * i;
			if (num1 != 0 && num1 <= num) {
				int cnt = 0;
				while (num1 > 0) {
					num1 -= k;
					cnt++;
				}
				if (num1 == 0) {
					ans1 = Math.min(ans1, cnt);
				}
			}
		}
		return ans1 == Integer.MAX_VALUE ? -1 : ans1;
	}

	public int minimumNumbers1(int num, int k) {
		if (num == 0) {
			return 0;
		}

		int last = num % 10;
		if (k == 0) {
			return last == 0 ? 1 : -1;
		}
		int ans3 = num % k == 0 ? num / k : Integer.MAX_VALUE;
		if (num < k || ((last % k) != 0 && ((last + 10) % k != 0))) {
			return ans3 == Integer.MAX_VALUE ? -1 : ans3;
		}
		if ((last % k) == 0) {
			if (last == k) {
				return 1;
			}
		}
		int ans1 = Integer.MAX_VALUE;
		if ((last % k) == 0) {
			if (last != 0) {
				ans1 = last / k;
			} else if (num % k == 0) {
				ans1 = num / k;
			}
		}
		int ans2 = Integer.MAX_VALUE;
		if ((last + 10) % k == 0) {
			ans2 = (last + 10) / k;
		}
		int ans = Math.min(Math.min(ans1, ans2), ans3);
		return ans == Integer.MAX_VALUE ? -1 : ans;
	}

}
